package com.yukefms.engine.interfaces;

import com.yukefms.engine.running.RunningContext;
import com.yukefms.message.KafkaConfig;
import com.yukefms.message.MessageProducer;
import com.yukefms.rule.interfaces.BARule;
import com.yukefms.rule.interfaces.BAStageRule;
import com.yukefms.rule.interfaces.RuleBuilder;

import java.util.List;
import java.util.Map;

/**
 * @Description The FMS engine interface defines basic functions for its lifecycle, which includes
 *  <ul>
 *      <li>Initilizing phase: configuring the BARules, message container, running context, and other related listener  </li>
 *      <li>Running phase: by reading the head message from container, the pointcloud in the message was parsed and feeded into
 *      reation part of engine. The reaction was proccessed based on the semantics of BARules and generate serveral sorts of running events,
 *      according to the running state of rules, i.e,
 *      <ul>
 *          <li>INACTIVED: inactived or not triggered</li>
 *          <li>ACTIVED: triggered</li>
 *          <li>FAILURE: there are three cases leading to failure, i.e., Time run out, try-time run out, and input error.</li>
 *      </ul>
 *      These running events, as status, will return to the client to inform the real running situation.
 *      </li>
 *      <li>Ending phase: Either following cases would be considered as FINISHED_WORK:
 *           <ol>
 *               <li>the configured rules are satisfied.</li>
 *               <li>the allowed time was run out.</li>
 *               <li>the allowed try-times was run out</li>
 *               <li>the number of error input messages was pass the threshold, which could be thougt as machine problem.</li>
 *           </ol>
 *      </li>
 *  </ul>
 * @Author Ping
 * @Date 2021/6/25 16:35
 **/
public interface FMSEngine {
    /**
     * for sending begining infor to the Front.
     */
    public static final String BEGIN_CODE = "00" ;
    public MessageProducer getProducer() ;
    public PointCloudReader getReader() ;
    public RunningContext currentContext() ;
    /**
     * send infor to the Front.
     * @param infor
     */
    public default void sendBeginInfor(String infor) {
        getProducer().send(KafkaConfig.TOPIC_RESPONSE, infor);
    }
    public void setBARule(BAStageRule rule) ;
    public BAStageRule getBARule() ;
    public void doInit() ;
    public void doInit(MessageProducer producer) ;
    public void startup() ;
    public void shutdown() ;

    /**
     * for mutil rules
     */
    public void setBARules(List<BAStageRule> ruleList) ;
    public BAStageRule currentRule() ;
    public boolean currentIsFinished() ;
    public boolean allFinished() ;
    public boolean hasNext() ;
    public void toNext() ;
    public void resetContext(BAStageRule newRule) ;
    public RunningContext getContextByRuleName(String ruleName) ;
    public Map<String, RunningContext> getRuleContextMap() ;



}
